<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	</body>
	<script>
		
		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if(r != null) return unescape(r[2]);
			return null;
		}
		
		function setCookie(name, value) {
			var Days = 30;
			var exp = new Date();
			exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
			document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
		}

		//读取cookies 
		function getCookie(name) {
			var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

			if(arr = document.cookie.match(reg))
				return unescape(arr[2]);
			else
				return null;
		}
		
		var userid = getQueryString('userid');
		var storeid = getQueryString('storeid');
		var type = getQueryString('type');
		var tourl = getQueryString('tourl');
		
		var urls = '';
		if(type == 'into'){
			
			console.log('tourl='+encodeURIComponent(tourl));			
			setCookie('tourl',tourl);
			
			urls = 'http://www.amyshirley.com/dianwu/php/index.php/store/User/Login/storeid/'+storeid;
			//window.location.href = urls;
			window.location.replace(urls);
		}
		else if(type == 'back'){
			setCookie('userid',userid);
			setCookie('storeid',storeid);
			
			console.log('userid='+userid);
			console.log('storeid='+storeid);
			
			tourl = getCookie('tourl');	
			setCookie('tourl','');				
			if(tourl != '' && tourl !=null && tourl!=undefined){
				urls = tourl;
			}
			else{
				urls = 'http://www.amyshirley.com/dianwu/index.html';
			}
			
			window.location.href = urls;
			
			//window.location.replace(urls);
		}
		else{
			console.log('im close');
			window.close();
		}
		
	</script>
</html>
